<div id="assetsPage">
    <div class="post">
        <h2 class="title">Assets</h2>
        <div class="entry">
            <script>
                $(function() {
                    $( "#asset_datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
                });
            </script>


            <input type="button" value="Add new" onclick="show('#new_asset')"/>


            <?php
         //   if ($this->session->userdata("admin")) {
            ?>
                <input type="button" value="Search" onclick="show('#searchAssets')"/>
                <input type="button" value="Clear Search" onclick="clearSearch()"/>
            <?php
        //    }
            ?>
            <div id="assets_result" class="info">
                <?= $message ?>
            </div>
            <script type="text/javascript">
                function searchAssets(num){
                    field=document.getElementById("searchAssetsForm"+num).field.value;
                    search=document.getElementById("searchAssetsForm"+num).search.value;
                    $("#assetsPage").load("<?= base_url(); ?>index.php?/admin_mis/assets/"+field+"/"+search);
                }
                function clearSearch(){
                    $("#assetsPage").load("<?= base_url(); ?>index.php?/admin_mis/assets/");
                }
            </script>
            <div id="new_asset" style="display: none;margin-bottom: 10px;">
                <?php $data['id'] = "asset_form" ?>
                <?= form_open_multipart('mis/saveAsset', $data); ?>
                <table>
                    <tr class="darker"><td class="half">Asset name</td><td><input type="text" class="wide" name="asset_name" value="<?php echo set_value('asset_name'); ?>"  /></td> </tr>
                    <tr class="lighter"><td class="half">Department</td><td>
                            <select name="department">
                                <?php foreach ($department as $type): ?>
                                    <option value="<?= $type->tid; ?>"><?= $type->name; ?></option>
                                <?php endforeach; ?>
                                </select>
                            </td> </tr>
                        <tr class="darker"><td class="half">Serial No.</td><td><input type="text" class="wide" name="serial_number" value="<?php echo set_value('serial_number'); ?>"  /></td> </tr>
                        <tr  class="lighter"><td>Purchased by</td><td><input type="text"  class="wide" name="purchased_by" value="<?php echo set_value('purchased_by'); ?>" /></td> </tr>
                        <tr class="darker"><td>Date of purchase</td><td><input type="text" class="wide"  name="date_purchased" value="<?php echo set_value('date_purchased'); ?>" id="asset_datepicker" /></td> </tr>
                        <tr  class="lighter"><td>No. of items purchased </td><td><input type="text"  class="wide" name="quantity" value="<?php echo set_value('quantity'); ?>" /></td> </tr>
                        <tr  class="darker"><td>Cost per asset</td><td><input type="text"  class="wide" name="cost" value="<?php echo set_value('cost'); ?>" /></td> </tr>

                        <tr><td colspan="2" style="text-align: right">
                                <input type="submit" value="Submit" />
                                <input type="button" value="Cancel" onclick="hide('#new_asset')"/>
                            </td></tr>
                    </table>
                    </form>
                </div>
                <div id="searchAssets" style="display: none;margin-bottom: 10px;">
                    <form id="searchAssetsForm1">
                        <input type="hidden" name="field" value="department"/>
                        <table>
                            <tr class="darker"><td class="half">Search by SBU</td>
                                <td><select name="search">
                                    <?php foreach ($department as $type): ?>
                                        <option value="<?= $type->tid; ?>"><?= $type->name; ?></option>
                                    <?php endforeach; ?>
                                    </select></td>
                            </tr>

                            <tr><td colspan="2" style="text-align: right">
                                    <input type="button" value="Submit" onclick="searchAssets(1)" />
                                    <input type="button" value="Cancel" onclick="hide('#searchAssets')"/>
                                </td></tr>

                        </table>
                    </form>
                    <form id="searchAssetsForm2">
                        <table>
                            <tr class="darker"><td class="half">Search by other fields</td>
                                <td><select name="field">
                                        <option value='all'>All</option>
                                        <option value='asset_name' >Asset Name</option>
                                        <option value='serial_number' >Serial number</option>
                                        <option value='purchased_by' >Purchased by</option>
                                        <option value='added_by'> Added by</option>
                                    </select></td>
                                <td><input type="text" name="search" class="wide"  value="<?php echo set_value('added_by'); ?>" /></td>
                            </tr>

                            <tr><td colspan="3" style="text-align: right">
                                    <input type="button" value="Submit" onclick="searchAssets(2)" />
                                    <input type="button" value="Cancel" onclick="hide('#searchAssets')"/>
                                </td></tr>

                        </table>
                    </form>
                </div>
                <div id="all_asset">
                <?= $tablet ?>
                <?= $pagina ?>
            </div>

        </div>
    </div>
</div>